<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>倒计时</title>
	</head>
	<body>
		<div id="d1"></div>
		<script>
			var d=new Date(2018,0,4,23,50);
			var timer;
			function f1(){
			var now=new Date();
			var t=d.getTime()-now.getTime();
			if(t<0){
				clearInterval(timer);
				d1.innerHTML="活动结束";
				return;
			}
			var hour=Math.floor(t/(1000*60*60)%24);
			hour=hour<10?"0"+hour:hour;
			var day=Math.floor(t/(1000*60*60*24));
			var minute=Math.floor(t/(1000*60)%60);
			minute=minute<10?"0"+minute:minute;
			var second=Math.floor(t/1000%60);
			second=second<10?"0"+second:second;
			var haominute=t%1000;
			if(day<1){
				d1.innerHTML=hour+":"+minute+":"+second+":"+haominute;
			}else{
				d1.innerHTML=day+"天"+hour+":"+minute+":"+second+":"+haominute;
			}
			}
			f1()
			timer=setInterval(f1,1000);
		</script>
	</body>
</html>
